/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dao.ThanhVienDAO;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.Thanhvien;

/**
 *
 * @author Tran Manh Linh
 */
@WebServlet(name = "xuLyDangNhap", urlPatterns = {"/xuLyDangNhap"})
public class xuLyDangNhap extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession(true);
        Thanhvien tv = new Thanhvien();
        String username = request.getParameter("tenDangNhap");
        String password = request.getParameter("matKhau");
        
        tv = ThanhVienDAO.logIn(username, password);
        if (tv != null) {
            session.setAttribute("user", tv);
            response.sendRedirect("firstPage");
        } else {
            response.sendRedirect("firstPage");
        }
    }
}
